﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OracleClient;
public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       string name = Name.Text;
            string st = staff.Text;
            string d = de.Text;
            

            string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";


            OracleConnection sqlCon = new OracleConnection(connet);
            if (sqlCon.State.Equals(ConnectionState.Closed))
            { sqlCon.Open(); }


            OracleCommand sqlComGet = new OracleCommand();
            sqlComGet.Connection = sqlCon;

            sqlComGet.CommandText = "select * from booksale.staff where 姓名='" + name + "' and 职工号='" + st + "'";
            OracleDataReader sqlDr = sqlComGet.ExecuteReader();
            

            if (sqlDr.Read() && d == "图书管理员" && code.Text == "hunan123")
            {
                string strsql = "insert into booksale.admin values('" + username.Text + "','" + pass.Text + "')";

                bool insert = ConnectSQL(strsql);

                if (insert)
                { Response.Write("<script>window.alert('注册成功')</script>"); }
                else { Response.Write("<script>window.alert('注册失败')</script>"); }
            }
            else { Response.Write("<script>alert('该职员不存在或者不是图书管理员')</script>"); }
           
            if (sqlCon.State.Equals(ConnectionState.Open))
            { sqlCon.Close(); }
        }
    public bool ConnectSQL(string strSqlCom)
    {
        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        OracleConnection con = new OracleConnection(connet);
        OracleCommand com = new OracleCommand(strSqlCom, con);
        try
        {
            if (con.State == System.Data.ConnectionState.Closed)
            { con.Open(); }
            com.ExecuteNonQuery();
            return true;


        }
        catch
        { return false; }
        finally
        { con.Close(); }
    }



    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("master/index.aspx");
    }
}
